package at.codebase.db.entities;

import java.util.ArrayList;
import java.util.List;

import at.codebase.db.DatabaseUtilities;

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;

/**
 * @author Daniel Marth <danielmarth@gmx.at>
 */
@Entity
public class EItemCollection {

	@Id
	private Long id;
	private List<Ref<EUser>> owners;
	private List<Ref<EItem>> items;
	@Index
	private String name;

	public EItemCollection() {

	}

	public EItemCollection(List<Ref<EUser>> o, List<Ref<EItem>> i, String n) {
		owners = new ArrayList<Ref<EUser>>(o);
		items = new ArrayList<Ref<EItem>>(i);
		name = n;
	}

	public EItemCollection(Ref<EUser> o, String n) {
		owners = new ArrayList<Ref<EUser>>();
		owners.add(o);
		items = new ArrayList<Ref<EItem>>();
		name = n;
	}

	public Long getId() {
		return id;
	}

	public List<EUser> getOwners() {
		return DatabaseUtilities.dereferenceList(owners);
	}

	public List<EItem> getItems() {
		return DatabaseUtilities.dereferenceList(items);
	}

	public void addItem(Ref<EItem> item) {
		items.add(item);
	}

	public void removeItem(Ref<EItem> item) {
		items.remove(item);
	}

	public String getName() {
		return name;
	}

}
